<template>
  <el-dropdown trigger="click" @command="handleSetLanguage">
    <div>
      <!-- <svg-icon class-name="size-icon" icon-class="size" /> -->
      <svg-icon icon-class="international" />
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item v-for="item of languageOptions" :key="item.value" :disabled="language===item.value" :command="item.value">
        {{
          item.label }}
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
export default {
  data() {
    return {
      languageOptions: [
        { label: '中文', value: 'zh_CN' },
        { label: '英文', value: 'en_US' },
        // { label: 'Small', value: 'small' },
        // { label: 'Mini', value: 'mini' }
      ]
    }
  },
  computed: {
    language() {
      return this.$store.getters.language
    }
  },
  methods: {
    handleSetLanguage(language) {
        this.$i18n.locale = language;//关键语句 
        this.$store.dispatch('app/setLanguage', language)
        this.refreshView()
        this.$message({
            message: 'Switch Language Success',
            type: 'success'
        })
    },
    refreshView() {
      // In order to make the cached page re-rendered
      // this.$store.dispatch('tagsView/delAllCachedViews', this.$route)

      const { fullPath } = this.$route

      this.$nextTick(() => {
        this.$router.replace({
          path: '/redirect' + fullPath
        })
      })
    }
  }

}
</script>
